package com.egao.orderB.controller;

import com.egao.common.core.annotation.ApiPageParam;
import com.egao.common.core.damon.results.PageResult2;
import com.egao.common.core.web.*;
import com.egao.common.core.annotation.OperLog;
import com.egao.orderB.entity.Warehouse;
import com.egao.orderB.service.WarehouseService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.ui.Model;


/**
 *
 * 仓库
 * @author : Doman
 * @date : 2021-12-23 16:29:28
 * @version ：1.0
 */

@Api(tags = "仓库")
@RestController
@RequestMapping("/api/orderB/warehouse")
public class WarehouseController extends BaseController {

	@Autowired
	private WarehouseService warehouseService;

	/**
	 * 分页查询列表
	 */
	@PreAuthorize("hasAuthority('orderB:warehouse:list')")
  @ApiOperation(value ="分页查询仓库",notes = "" +
    "limit:每页显示几行 必填\n" +
    "page:第几页 必填\n" +
    " \n\n\n" +
    "返回的结果:\n" +
    "id:id\n" +
    "name:仓库名称\n" +
    "remark:托盘数\n" +
    "orderNum:排序\n" +
    "createTime:创建时间\n" +
    "createUser:创建人\n" +
    "updateTime:更新时间\n" +
    "updateUser:更新人\n" +
    "",httpMethod = "POST")
  @ApiPageParam
  @PostMapping("/list")
  public JsonResult page(PageResult2<T> page, Warehouse warehouse) throws Exception{
    return warehouseService.list(page, warehouse, getLoginUser());
  }

  /**
   * 查询全部仓库
   */
  @PreAuthorize("hasAuthority('orderB:warehouse:list')")
  @ApiOperation("查询全部仓库")
  @PostMapping("/listAll")
  public JsonResult list(Warehouse warehouse){
    return warehouseService.list(warehouse, getLoginUser());
  }

  /**
   * 根据id查询仓库
   */
  @PreAuthorize("hasAuthority('orderB:warehouse:list')")
  @ApiOperation("根据id查询仓库")
  @PostMapping("/get")
  public JsonResult get(Warehouse warehouse) {
    return warehouseService.getById(warehouse);
  }


  /**
   * 添加仓库
   */
  @PreAuthorize("hasAuthority('orderB:warehouse:save')")
  @OperLog(value = "仓库", desc = "添加", param = false, result = true)
  @ApiOperation(value ="添加仓库",notes = "" +
    "name:仓库名称\n" +
    "remark:托盘数\n" +
    "orderNum:排序\n" +
    "",httpMethod = "POST")
  @PostMapping("/save")
  public JsonResult save(Model model, Warehouse warehouse) {
    return warehouseService.save(warehouse, getLoginUser());
  }

  /**
   * 修改仓库
   */
  @PreAuthorize("hasAuthority('orderB:warehouse:update')")
  @OperLog(value = "仓库", desc = "修改", param = false, result = true)
  @ApiOperation(value ="修改仓库",notes = "" +
    "id:id\n" +
    "name:仓库名称\n" +
    "remark:托盘数\n" +
    "orderNum:排序\n" +
    "",httpMethod = "POST")
  @PostMapping("/update")
  public JsonResult update(Model model, Warehouse warehouse) {
    return warehouseService.update(warehouse, getLoginUser());
  }

  /**
   * 删除仓库
   */
  @PreAuthorize("hasAuthority('orderB:warehouse:remove')")
  @OperLog(value = "仓库", desc = "删除", result = true)
  @ApiOperation(value ="删除仓库",notes = "" +
    "id:id\n" +
    "",httpMethod = "POST")
  @PostMapping("/remove")
  public JsonResult remove(Warehouse warehouse ) {
    return warehouseService.remove(warehouse, getLoginUser());
  }

}
